
package com.fx.apartment.modules.dynamic.controller;

import com.fx.apartment.common.tool.lock.RedisLock;
import com.fx.apartment.modules.dynamic.service.IDynamicService;
import com.fx.apartment.common.support.Condition;
import com.fx.apartment.common.support.Query;
import com.fx.apartment.common.tool.api.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fx.apartment.modules.dynamic.entity.ThumbsUp;
import com.fx.apartment.modules.dynamic.service.IThumbsUpService;


/**
 * 朋友圈点赞 控制器
 *
 * @author QinXueFeng
 * @since 2021-04-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/thumbsup")
@Api(value = "朋友圈点赞", tags = "朋友圈点赞接口")
public class ThumbsUpController {

	private final IThumbsUpService thumbsUpService;

	private final IDynamicService dynamicService;
	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入thumbsUp")
	public R<ThumbsUp> detail(ThumbsUp thumbsUp) {
		ThumbsUp detail = thumbsUpService.getOne(Condition.getQueryWrapper(thumbsUp));
		return R.data(detail);
	}

	/**
	 * 分页 朋友圈点赞
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入thumbsUp")
	public R<IPage<ThumbsUp>> list(ThumbsUp thumbsUp, Query query) {
		IPage<ThumbsUp> pages = thumbsUpService.page(Condition.getPage(query), Condition.getQueryWrapper(thumbsUp));
		return R.data(pages);
	}

	/**
	 * 新增 朋友圈点赞
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入thumbsUp")
	@RedisLock("thumbsup::save")
	public R save(@Valid @RequestBody ThumbsUp thumbsUp) {
		return R.status(thumbsUpService.save(thumbsUp)&&dynamicService.updateCommentNum(thumbsUp.getDynamicId()));
	}
	
	/**
	 * 删除 朋友圈点赞
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(thumbsUpService.deleteByIds(ids));
	}

	
}
